<!DOCTYPE html>
<html>
  <head>
    <% include global/meta.html %>
    <% include global/top-css.html %>
    <title>yuscms</title>
</head>
  <body>

        <main class="main" data-info="<%=admin.permission%>">
          <div class="ys-admin-pos c-a1a3aa">
            首页<span class="f-sum">></span><span class="c-565b6d">管理员等级</span>
          </div>
          <div class="ys-admin-tablist">
              <div class="ys-admin-tab-header row justify-content-b">
                  <p class="f-14 c-565b6d pl-8 pt-6">管理员等级</p>
                  <a href="/admin/level/add" class="btn-add"><i class="ico ico-plus f-16 pos-r">+</i>新增</a>
              </div>
      
              <div class="mr-10 ml-10" v-loading="loading">
              <table class="table table-hover ml-10">
                    <thead class="table-th">
                        <tr>
                            <th>编号</th>
                            <th>等级</th>
                            <th>权限</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                   
                    <tbody class="table-border">
                        <tr v-for="item in list" :key="item.id">
                            <td>{{item.id}}</td>
                            <td>{{item.level_name}}</td>
                            <td>{{item.level_info}}</td>
                           
                            <td>
                              <a :href="'/admin/level/edit?id='+item.id"><i class="ico ico-edit mr-10 pos-r t-4"></i></a>
                              <a href="javascript:;" @click="isDel(item.id)"><i class="ico ico-del pos-r t-4"></i></a>
                             </td>
                        </tr>
                   </tbody>
              </table>
      
              </div>
             
          </div>
        </main>
     
	<% include global/all-js.html %>
	<script>
		var vm = new Vue({
			el:'.main',
			data:{
        loading: true,
      list: [] //渲染页面的列表数据
			},
			methods:{
			
        getData() {
      var _this = this;
      axios
        .get("/api/admin/level")
        .then(data => {
          _this.list = data.data.data;
          _this.loading = false;
        })
        .catch(error => {
          console.error(error);
        });
    },
    isDel(id) {
      let _this = this;
      if(!hasPermission('12')){
          tipsWarn(_this,'对不起,您没有操作权限^_^');
          return
      }
      axios
        .get("/api/admin/level/isDel", {
          params: { id: id }
        })
        .then(data => {
          let filterData = data.data;
          if (filterData.success) {
            if (filterData.data.length == 0) {
              _this.del(id);
            } else {
              _this.tipsWarn("已经有管理员属于当前等级，不能删除！");
            }
          } 
        })
        .catch(error => {
          console.error(error);
        });
    },
    del(id) {
      let _this = this;
      axios
        .get("/api/admin/level/del", {
          params: { id: id }
        })
        .then(data => {
          let filterData = data.data;
          if (filterData.success && filterData.data.affectedRows === 1) {
             tips(_this,"删除成功！");

            _this.getData();
          }
        })
        .catch(error => {
          console.error(error);
        });
    }
  },

  watch: {
    list: {
      handler: function(val, oldval) {
      },
      deep: true
    }
  },
  created: function() {
    this.getData();
  },
  mounted: function() {}
		});
	</script>	
	</body>
</html>